package icu.groot.alan.hotel.util.webmvc;

import icu.groot.alan.hotel.util.interceptor.AdminInterceptor;
import icu.groot.alan.hotel.util.interceptor.IdentityInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
//    }

    @Resource
    IdentityInterceptor interceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new IdentityInterceptor()).addPathPatterns(
                "/acc/identity/*",
                "/acc/update/password",
                "/acc/oneself",
                "/order/generate",
                "/order/purchase/*",
                "/order/list",
                "/order/refund/*",
                "/acc/topup/*",
                "/comment/list/*",
                "/comment/add/**"
        );
        registry.addInterceptor(new AdminInterceptor()).addPathPatterns(
                "/admin/**"
        ).excludePathPatterns(
                "/admin/login"
        );
    }
}
